package org.hackystat.devcathlon.engine.profile;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hackystat.devcathlon.engine.user.User;

/**
 * This class contains the definition of a user's profile.
 * @author Anthony Du
 */
public class Profile implements Serializable {
  /** Support serialization. */
  private static final long serialVersionUID = 1L;
  /** Primary key reference id. */
  private Long id;
  /** The User account. */
  private User user;
  /** Screen name. */
  private String screenName = "";
  /** User's First name. */
  private String firstName = "";
  /** User's Last name. */
  private String lastName = "";
  /** User's Biographical Information. */
  private String bioInfo = "";
  /** User's Gender. */
  private String gender = "";
  /** User's Location. */
  private String location = "";
  /** User's contact info. */
  private String contact = "";
  /** User's avatar at default application resource path. */
  private String avatarPath = System.getProperty("user.home") 
                              + "/.hackystat/devcathlon/avatars/profile/";
  /** User's avatar file. */
  private String avatar = "Dummy_user.png";
  /** User's email addresses. */
  private List<String> emails = new ArrayList<String>();
  /** Email address of User. */
  private Set<String> emailAddresses = new HashSet<String>();
  
  /**
   * Profile default constructor.
   */
  public Profile() {
    // empty constructor
  }
  
  /**
   * Profile derived constructor. 
   * This constructor derives other common attributes given a user's email.
   * @param email user's email via Hackystat.
   */
  public Profile(String email) {
    if (email.indexOf('@') > 0) {
      this.screenName = email.substring(0, email.indexOf('@'));
      this.emailAddresses.add(email);
    }
  }
  
  /**
   * Profile constructor. 
   * @param screenName user's screen name
   * @param firstName user's first name
   * @param lastName user's last name
   * @param bioInfo user's bio info
   */
  public Profile(String screenName, String firstName, String lastName, String bioInfo) {
    this.screenName = screenName;
    this.firstName = firstName;
    this.lastName = lastName;
    this.bioInfo = bioInfo;
  }
  
  /**
   * Set the id of this profile.
   * @param id the id to set
   */
  public void setId(Long id) {
    this.id = id;
  }

  /**
   * Return the id of this profile.
   * @return the id
   */
  public Long getId() {
    return id;
  }
  
  /**
   * Set the User account for this Profile.
   * @param user the user to set
   */
  public void setUser(User user) {
    this.user = user;
  }

  /**
   * Return the User account of this Profile.
   * @return the user
   */
  public User getUser() {
    return user;
  }

  /**
   * Returns the user's screenName.
   * @return screenName
   */
  public String getScreenName() {
    return screenName;
  }

  /**
   * Sets the user's screenName.
   * @param screenName user's screenName
   */
  public void setScreenName(String screenName) {
    if (null == screenName) {
      this.screenName = "";
    }
    else {
      this.screenName = screenName;
    }
  }

  /**
   * Returns the user's first name.
   * @return user's first name
   */
  public String getFirstName() {
    return firstName;
  }

  /**
   * Sets the user's first name.
   * @param firstName user's first name.
   */
  public void setFirstName(String firstName) {
    if (null == firstName) {
      this.firstName = "";
    }
    else {
      this.firstName = firstName;
    }
  }

  /**
   * Returns the user's last name.
   * @return user's last name
   */
  public String getLastName() {
    return lastName;
  }

  /**
   * Sets the user's last name.
   * @param lastName user's last name.
   */
  public void setLastName(String lastName) {
    if (null == lastName) {
      this.lastName = "";
    }
    else {
      this.lastName = lastName;
    }
  }

  /**
   * Returns the user's full name.
   * @return user's full name
   */
  public String getFullName() {
    if ("".equals(this.firstName) || "".equals(this.lastName)) {
      return " ";
    } 
    else {
      return this.firstName + " " + this.lastName;
    }
  }
  
  /**
   * Set the email address for this profile.
   * @param emailAddresses the emailAddresses to set
   */
  public void setEmailAddresses(Set<String> emailAddresses) {
    this.emailAddresses = emailAddresses;
  }

  /**
   * Return the email addresses for this profile.
   * @return the emailAddresses
   */
  public Set<String> getEmailAddresses() {
    return emailAddresses;
  }
  
  /**
   * Returns the user's email addresses.
   * @return user's email addresses
   */
  public List<String> getEmails() {
    return emails;
  }
  
  /**
   * Add an email address.
   * @param email email address to be added
   * @return if address was successfully added to email list
   */
  public boolean addEmail(String email) {
    if (email.indexOf('@') > 0) {
//      return emails.add(email);
      return emailAddresses.add(email);
    }
    else {
      return false;
    }
  }
  
  /**
   * Remove an email address.
   * @param email email address to be removed
   * @return if address was successfully removed from email list
   */
  public boolean removeEmail(String email) {
    if (emails.contains(email)) {
      return emails.remove(email);
    }
    else {
      return false;
    }
  }

  /**
   * Returns the user's bio information.
   * @return user's bio info
   */
  public String getBioInfo() {
    if ("".equals(bioInfo)) {
      bioInfo = "Say something about yourself. Go to the Profile Manage submenu to edit this box.";
    }
    return bioInfo;
  }

  /**
   * Sets the user's bio information.
   * @param bioInfo user's bio info
   */
  public void setBioInfo(String bioInfo) {
    this.bioInfo = bioInfo;
  }
  
  /**
   * Returns the user's gender.
   * @return user's gender
   */
  public String getGender() {
    return gender;
  }
  
  /**
   * Sets the user's gender.
   * @param gender user's gender
   */
  public void setGender(String gender) {
    this.gender = gender;
  }
  
  /**
   * Returns the user's location.
   * @return user's location
   */
  public String getLocation() {
    return location;
  }
  
  /**
   * Sets the user's location.
   * @param location user's location
   */
  public void setLocation(String location) {
    this.location = location;
  }
  
  /**
   * Returns the user's contact info.
   * @return user's contact info
   */
  public String getContact() {
    return contact;
  }
  
  /**
   * Sets the user's contact info.
   * @param contact user's contact info
   */
  public void setContact(String contact) {
    this.contact = contact;
  }
  
  /**
   * Returns the user's avatar location.
   * @return user's avatar location
   */
  public String getAvatar() {
    if ("".equals(avatar)) {
      avatar = "Dummy_user.jpg";
    }
    return avatar;
  }

  /**
   * Sets the user's avatar location.
   * @param avatar user's avatar location
   */
  public void setAvatar(String avatar) {
    if (!("".equals(avatar))) {
      this.avatar = avatar;
    }
  }
}
